package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/namsral/flag"
	"log"
	"meinong/hardware/controller"
	"meinong/hardware/handler"
	"net/http"
	"os"
	"path/filepath"

	"meinong/hardware/initialize"
	"meinong/hardware/server"
	"meinong/hardware/ws"
)

var Haddr = flag.String("Haddr", "COM3", "address to listen")
var Taddr = flag.String("Taddr", "COM4", "address to listen")
var wsAddr = flag.String("ws_addr", ":9090", "websocket address to listen")
var addr = flag.String("addr", ":8080", "address to listen")

func main() {
	flag.Parse()

	logger, err := server.NewZapLogger()
	if err != nil {
		log.Fatalf("cannot create logger: %v", err)
	}
	//redis Init
	initialize.InitRedis()
	//CalculatorHead Init
	initialize.InitCalculatorHead(*Haddr)
	//CalculatorTail Init
	//initialize.InitCalculatorTail(*Taddr)


	//waiting := make(chan int)
	logger.Info("Ws开始工作====")
	go ws.Start(*wsAddr, logger)

	logger.Info("计数器开始工作====")
	//go Location(*Haddr,p,true)
	go handler.LocationV2(true)
	//<-waiting

	r := gin.Default()
	str, _ := os.Getwd()
	fmt.Println(str)

	r.LoadHTMLGlob(filepath.Join(os.Getenv("GOPATH"), "gitee.com/meinongyihe/meinong/tree/main/server/hardware/template/**/*"))
	//r.LoadHTMLGlob("template/**/*") //加载当前目录下所有的文件
	r.Static("/assets", "./assets")

	r.GET("/", func(c *gin.Context) {
		c.HTML(http.StatusOK, "index/index.html", gin.H{
			"title": "首页",
		})
	})
	r.GET("api/index/PlanData", controller.GetPlanData)
	r.POST("api/index/PlanData", controller.PostPlanData)
	r.Run(":8082")

}






